package com.qianying.controller.admin;

import com.qianying.comment.CommonResult;
import com.qianying.entity.Region;
import com.qianying.service.RegionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/region")
@Tag(name = "大区管理", description = "大区信息管理接口")
public class RegionController {

    @Autowired
    private RegionService regionService;

    @PostMapping("/saveRegion")
    @Operation(summary = "添加大区", description = "根据传入的大区信息创建新的大区记录")
    public CommonResult<?> save(@RequestBody Region region) {
        return regionService.saveRegion(region);
    }

    @PostMapping("/updateRegion")
    @Operation(summary = "更新大区", description = "根据传入的大区信息更新已存在的大区记录")
    public CommonResult<?> update(@RequestBody Region region) {
        return regionService.updateRegion(region);
    }

    @PostMapping("/deleteRegion")
    @Operation(summary = "删除大区", description = "根据大区ID删除对应的大区记录")
    public CommonResult<?> delete(@PathVariable @Parameter(description = "大区ID") Long id) {
        return regionService.deleteRegion(id);
    }

    @GetMapping("/getRegionById")
    @Operation(summary = "获取单个大区", description = "根据大区ID查询对应的大区详情")
    public CommonResult<?> getById(@PathVariable @Parameter(description = "大区ID") Long id) {
        return regionService.getRegionById(id);
    }

    @GetMapping("/listRegions")
    @Operation(summary = "获取所有大区", description = "查询所有大区信息列表")
    public CommonResult<?> list() {
        return regionService.listRegions();
    }

    @GetMapping("/pageRegions")
    @Operation(summary = "分页查询大区", description = "根据页码和每页数量分页查询大区信息")
    public CommonResult<?> page(
            @RequestParam @Parameter(description = "页码，从1开始") Integer pageNum,
            @RequestParam @Parameter(description = "每页数量") Integer pageSize
    ) {
        return regionService.pageRegions(pageNum, pageSize);
    }

    @GetMapping("/listByCustomerId")
    @Operation(summary = "根据客户ID查询大区", description = "查询指定客户关联的所有大区信息")
    public CommonResult<?> listByCustomerId(
            @RequestParam @Parameter(description = "客户ID") Long customerId
    ) {
        return regionService.listByCustomerId(customerId);
    }
}